const express = require("express")
const router = express.Router()

const permissionController = require("../controllers/permissionController")
const { body, query } = require("express-validator")

// router.use(function timeLog(req, res, next) {
//     console.log('Time: ', Date.now())
//     //模块路由中检测是否携带了 token
//     if (!req.auth) {
//         return res.send({
//             status: 403,
//             message: "缺少token"
//         });
//     }
//     next()
// })
// 引入中间件
const checkPermission = require('../middleware/checkPermission');
const auth = require('../middleware/auth');

// 1. 添加权限
router.post("/add", auth, checkPermission("system_permiss_add"), permissionController.addpermission)
// 2. 删除权限-软删除
router.get("/del_f", auth, checkPermission("system_permiss_delete"), permissionController.del_permis_f)
router.get("/start", auth, checkPermission("system_permiss_delete"), permissionController.start)
// 3. 删除权限-真删除
router.get("/del_t", auth, checkPermission("system_permiss_delete"), permissionController.del_permis_t)
// 4. 修改权限-获取数据
router.get("/get", auth, checkPermission("system_permiss_delete"), permissionController.permis_get)
// 5. 修改权限-设置数据
router.post("/set", auth, checkPermission("system_permiss_edit"), permissionController.permis_set)
// 6. 为权限添加子项权限
router.post("/add_son", auth, checkPermission("system_permiss_add"), permissionController.add_son_permis_c)
// 7. 权限列表搜索+分页
router.get("/list", auth, checkPermission("system_permiss_list"), permissionController.permis_list_c)
// 8. 全部权限
router.get("/all", auth, checkPermission("system_permiss_list"), permissionController.permis_all)
// 8. 全部权限父级
router.get("/allfather", auth, checkPermission("system_permiss_list"), permissionController.permis_all_father)
// 9. 获取用户对应的所以权限
router.get("/get_permissions",auth, permissionController.getUserPermissions)
// 10. 获取角色对应的所以权限
router.get("/getrole_permissions", auth, checkPermission("system_role_set"), permissionController.getRolePermissions)

module.exports = router